#!/bin/bash

# GitHub Token 设置脚本

echo "GitHub Token 设置助手"
echo "===================="

echo "请按照以下步骤获取GitHub Token："
echo ""
echo "1. 访问: https://github.com/settings/tokens"
echo "2. 点击 'Generate new token' → 'Generate new token (classic)'"
echo "3. 设置以下信息："
echo "   - Note: GitHub Package Finder"
echo "   - Expiration: 根据需要选择（建议90天）"
echo "   - Scopes: 至少选择 'public_repo'"
echo "4. 点击 'Generate token'"
echo "5. 复制生成的token"
echo ""

read -p "请输入您的GitHub Token: " token

if [ -z "$token" ]; then
    echo "错误: 未输入token"
    exit 1
fi

# 设置环境变量
export GITHUB_TOKEN="$token"

# 添加到bashrc（可选）
read -p "是否将token添加到 ~/.bashrc 以便永久保存? (y/n): " save_permanent

if [ "$save_permanent" = "y" ] || [ "$save_permanent" = "Y" ]; then
    echo "export GITHUB_TOKEN=\"$token\"" >> ~/.bashrc
    echo "✅ Token已添加到 ~/.bashrc"
    echo "请运行 'source ~/.bashrc' 或重新打开终端"
fi

echo ""
echo "✅ Token设置完成！"
echo "现在可以运行: python3 github_package_finder.py"
echo ""
echo "注意: 请妥善保管您的token，不要分享给他人"
